#!/usr/bin/env ruby
#encoding: utf-8

$:.unshift(File.expand_path(File.dirname(__FILE__))) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))

require 'optparse'

$hash_options = {mail: 'gmail'}

OptionParser.new do |opts|
  opts.banner = "Usage: intent_to_buy [options]"
  opts.on('-m [163|gmail|mstr|sendmail]', '--mail [163|gmail|mstr|sendmail]', "Specify the mail argument") do |v|
    if ['163', 'gmail', 'mstr', 'sendmail'].include? v
      $hash_options[:mail] = v
    else
      puts opts
    end
  end
  opts.on('-v', '--version', 'Display the version') do
    puts "0.1.0.0"
    exit
  end
  opts.on('-h', '--help', 'Display this help') do
    puts opts
    exit
  end
end.parse!

require 'backend/crawler/crawler'
crawler = Crawler::WebCrawler.new

require 'backend/data/data_processor'
DB_VTB::DataProcessor.new crawler

thread = crawler.crawl
thread.join

# threads = []
# threads << thread
# 
# require 'thwait'
# ThreadsWait.all_waits(*threads)
